//
//  LineCell.m
//  HappyTrip
//
//  Created by dlios on 15-3-24.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "LineCell.h"

@implementation LineCell

- (void)dealloc
{
    [_recommend release];
    [_lineLabel release];
    [_titleLabel release];
    [_texLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
        self.titleImage = [[UIImageView alloc] init];
        [self.titleLabel addSubview:self.titleImage];
        [_titleImage release];
        [_titleLabel release];
        
        self.lineLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.lineLabel];
        self.labelImage = [[UIImageView alloc] init];
        [self.lineLabel addSubview:self.labelImage];
        [_labelImage release];
        [_lineLabel release];
        
        self.texLabel = [[UILabel alloc] init];
        self.texLabel.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [self.contentView addSubview:self.texLabel];
        [_texLabel release];
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    CGFloat width = self.contentView.bounds.size.width;
    CGFloat heigth = (self.contentView.bounds.size.height - 30);
    
    self.titleLabel.frame = CGRectMake(10, 0, width - 20, 30);
    if (self.recommend.title != nil) {
        
        self.titleLabel.text = [NSString stringWithFormat:@" %@", self.recommend.title];
        self.titleImage.frame = CGRectMake(0, 5, 3, 20);
        self.titleImage.image = [UIImage imageNamed:@"ticket_@2x.png"];
        
        self.lineLabel.frame = CGRectMake(10, 35, width - 20, heigth - 5);
        self.lineLabel.text = [NSString stringWithFormat:@"%@", [[self.recommend.data objectAtIndex:0] objectForKey:@"url"]];
        
        self.labelImage.frame = CGRectMake(0, 0, self.lineLabel.bounds.size.width, self.lineLabel.bounds.size.height * 2 / 3);
        NSString *str = [[self.recommend.data objectAtIndex:0] objectForKey:@"cover"];
        NSURL *url = [NSURL URLWithString:str];
        [self.labelImage setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
        
        self.texLabel.frame = CGRectMake(12.5, heigth * 2 / 3 + 35, width - 25, heigth / 3 - 7.5);
        self.texLabel.text = [NSString stringWithFormat:@"%@\n%@", [[self.recommend.data objectAtIndex:0] objectForKey:@"title"], [[self.recommend.data objectAtIndex:0] objectForKey:@"text"]];
        self.texLabel.numberOfLines = 0;
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
